package com.zimin.cloud.system.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.zimin.cloud.mine.pojo.system.business.AccountBO;
import com.zimin.cloud.system.pojo.entity.AccountPost;
import com.zimin.cloud.system.mapper.AccountPostMapper;
import com.zimin.cloud.system.service.IAccountPostService;
import com.zimin.mapper.injector.InjectServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.Collection;

/**
 * <p>
 * 用户岗位关联表 服务实现类
 * </p>
 *
 * @author zimin
 * @since 2022-01-24 17:29
 */
@Service("accountPostService")
@Slf4j
public class AccountPostServiceImpl extends InjectServiceImpl<AccountPostMapper, AccountPost> implements IAccountPostService {

    @Override
    public boolean removeByPostIds(Collection<? extends Serializable> idList) {
        return remove(Wrappers.<AccountPost>lambdaQuery().in(AccountPost::getPostId, idList));
    }

    @Override
    public boolean save(AccountBO accountBO) {
        var accountPost = AccountPost.builder()
                .accountId(accountBO.getId())
                .postId(accountBO.getPostId())
                .build();
        return save(accountPost);
    }

    @Override
    public boolean update(AccountBO accountBO) {
        return update(Wrappers.<AccountPost>lambdaUpdate().set(AccountPost::getPostId,
                accountBO.getPostId()).eq(AccountPost::getAccountId, accountBO.getId()));
    }
}
